package com.theme.passport.service.theme.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.theme.common.mvc.utils.PageUtils;
import com.theme.common.mvc.utils.Query;
import com.theme.passport.dao.theme.UserFollowDao;
import com.theme.passport.entity.theme.UserFollowEntity;
import com.theme.passport.service.theme.UserFollowService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("userFollowService")
public class UserFollowServiceImpl extends ServiceImpl<UserFollowDao, UserFollowEntity> implements UserFollowService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String userId = (String) params.get("userId");
        String fansId = (String) params.get("fansId");
        IPage<UserFollowEntity> page = this.page(
                new Query<UserFollowEntity>().getPage(params),
                new QueryWrapper<UserFollowEntity>()
                        .eq(StringUtils.isNotBlank(userId), "user_id", userId)
                        .eq(StringUtils.isNotBlank(fansId), "fans_id", userId)
                        .orderByDesc("created")
        );
        return new PageUtils(page);
    }

}